/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.strategy;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Component;

import cn.hutool.core.collection.CollectionUtil;

@Component
public class FastenerStandardCodeGenerationStrategy implements FastenerCodeGenerationStrategy {

    @Override
    public List<String> generateCodes(FastenerCodeContext context) {
        String fastenerGrade = context.getFastenerGrade();
        Integer diameterCode = context.getDiameterCode();
        String surfaceTreatment = context.getSurfaceTreatment();
        List<String> surfaceTreatmentList = Arrays.asList(surfaceTreatment.split(","));
        boolean padZero = context.isPadZeroForSingleDigit();
        List<String> result = new ArrayList<>();

        // 判断是否补0
        String formattedSize = padZero && diameterCode < 10
            ? String.format("%02d", diameterCode)
            : String.valueOf(diameterCode);

        if (CollectionUtil.isNotEmpty(surfaceTreatmentList)) {
            for (String treatment : surfaceTreatmentList) {
                if(context.isAddDashNumber()){
                    result.add(fastenerGrade + treatment + formattedSize);
                }else {
                    result.add(fastenerGrade + treatment);
                }
            }
        }
        return result;
    }
}
